$(function () {
    $("#goodsList").gridTable({
        url: "goods/pageGoods",
        columns: [
            {title: "商品图片", field: "goodsImg", format: toImg},
            {title: "商品名称", field: "goodsName"},
            {title: "基准价", field: "goodsMarketPrice", dataType:"decimal"},
            {title: "供应价", field: "goodsSellPrice", dataType: "decimal"},
            {title: "结算价", field: "goodsSettlementPrice", dataType: "decimal"},
            {title: "单位", field: "goodsUnit"},
            {title: "规格", field: "goodsSpec"},
            {title: "箱规", field: "boxSpec"},
            {title: "条码", field: "goodsBarCode"},
            {title: "商品类型", field: "goodsTypeName"},
            {title: "供应商", field: "orgName"},
            {title: "创建时间", field: "createTime"}
        ],
        pageSize: 10,
        idField: "id",
        infoUrl: "goods/outerGoodsInfo.html",
        editUrl: "goods/outerGoodsEdit.html",
        delUrl: "goods/delGoods"
    });
});

function toImg(url) {
    return "<img src='"+url+"' width='40' height='40'>";
}
//上架商品
function add1() {
    var gridTable = $$selection.get("gridTable","goodsList");
    var selectedRows = gridTable.getSelectedRows();
    if (selectedRows.length === 0) {
        $.error("请选择一个商品");
        return false;
    }
    if (selectedRows.length > 1) {
        $.error("只允许选择一条数据");
        return false
    }
    var row = selectedRows[0];
    var id = row.getData().id;
    // console.log(id)
    var dialog = $.openIframeDialog({
        title:"新增上架商品",
        url: "goods/upGoods.html",
        param: {
            id: id
        },
        afterSubmit: function () {
            gridTable.reloadData();
            return true;
        }
        // buttons: {
        //     ok: {
        //         onclick: function () {
        //                 gridTable.reloadData();
        //                 dialog.close();
        //         }
        //     }
        // }
    });
}

